package mrusanov.team

import mrusanov.nation.Nation
import mrusanov.buildings.{ ClubBuildings, Arena }
import mrusanov.money.ClubBudget
import mrusanov.localization.Localization
import mrusanov.player.Player

class Club(val nameKey: String) {
	def name = Localization(nameKey)
	val firstTeam = new Team(this, name + "", FirstTeam)
	val secondTeam = new Team(this, name + "-2", SecondTeam)
	val juniorTeam = new Team(this, name + " junior", JuniorTeam)
	val clubStaff = new ClubStaff
	val clubBudget = new ClubBudget

	val buildings = new ClubBuildings(this)

	var nation: Nation = _

	def team(level: TeamLevel) = level match {
		case FirstTeam => firstTeam
		case SecondTeam => secondTeam
		case JuniorTeam => juniorTeam
	}

	def eloRating = firstTeam.rating

	def teams = List(firstTeam, secondTeam, juniorTeam)

	def removePlayer(player: Player) {
		val removedFromFirstTeam = firstTeam.removePlayer(player)
		if (removedFromFirstTeam) {
			return
		}

		val removedFromSecondTeam = secondTeam.removePlayer(player)
		if (removedFromSecondTeam) {
			return
		}

		val removedFromThirdTeam = juniorTeam.removePlayer(player)
		if (!removedFromThirdTeam) {
			throw new IllegalArgumentException("Player doesn't belong to team!")
		}
	}

	override def toString = name
}

sealed abstract class TeamLevel
case object FirstTeam extends TeamLevel
case object SecondTeam extends TeamLevel
case object JuniorTeam extends TeamLevel